<?php
/**
 * Created by PhpStorm.
 * User: HouJie
 * Date: 2018-4-3
 * Time: 15:07
 */

namespace Bqdove\Container;

use Bqdove\Cache\FileCache;
use Bqdove\Cache\RedisCache;

class Container
{
    protected static $data;

    /**
     * 服务提供者
     * @var array
     */
    protected static $providers = [
        'file' => FileCache::class,
        'redis' => RedisCache::class
    ];

    /**
     * 绑定到服务容器
     * @param $name
     * @param \Closure $resolver
     */
    public static function bind($name, \Closure $resolver)
    {
        static::$data[$name] = $resolver;
    }

    /**
     *
     * @param $name
     * @return mixed
     * @throws \Exception
     */
    public static function make($name)
    {
        if (isset(static::$data[$name])) {
            $resolver = static::$data[$name];
            return $resolver();
        }

        throw new \Exception("Alias " . $name . " does not exist in the container register");
    }

    /**
     * 返回服务容器支持的类型
     * @return array
     */
    public static function getContainer($key)
    {
        return self::$providers[$key];
    }

}
